﻿using AutoMapper;
using HuaHan.WorkTicket.Domain;
using HuaHan.WorkTicket.Domain.Model;
using HuaHan.WorkTicket.Domain.Repositories;
using HuaHan.WorkTicket.Domain.Repositories.EntityFramework;
using HuaHan.WorkTicket.ServiceContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WorkTicket.Application.Implementation
{
    public class EmployeeServiceImpl : BaseServiceImpl<Employee>,IEmployeeService
    {

        #region Private Fields
        private const string NO_STRING = "EMP";
        private UnitOfWork unitOfWork = new UnitOfWork();
        #endregion

        public EmployeeServiceImpl()
        {
            base.Repository = unitOfWork.EmployeeRepository;
            base.UnitOfWork = this.unitOfWork;
        }

        public string GetNextNo()
        {
            string currentYear = DateTime.Now.Year.ToString("0000");
            string currentMonth = DateTime.Now.Month.ToString("00");
            string currentDay = DateTime.Now.Day.ToString("00");
            string dateString = currentYear + currentMonth + currentDay;
            if (this.GetAll().Count() == 0)
            {
                return NO_STRING + dateString + "001";
            }
            else
            {
                string MaxNo = base.Repository.GetAll().Max(c => c.EID);
                int temp = int.Parse(MaxNo.Substring(MaxNo.Length - 3, 3));
                return NO_STRING + dateString + (temp + 1).ToString("000");
            }
        }

    }
}
